package net.iceflow.dunsel.client;

import net.iceflow.dunsel.client.listener.DisconnectionListener;
import net.iceflow.dunsel.client.listener.FailedConnectionListener;
import net.iceflow.dunsel.client.listener.SuccessfulConnectionListener;
import net.iceflow.dunsel.commons.Subscribable;

/**
 * Main facade for the Dunsel client library.
 */
public interface ClientFacade {

    /**
     * Connects to a Dunsel server.
     * @param address IP / hostname of the server
     * @param port TCP/IP Port on which the server is listening
     * @throws IllegalStateException If a connection attempt is made while a connection is already active
     */
    void connect(final String address, final int port) throws IllegalStateException;

    /**
     * Disconnects from a previously connected server connection.
     */
    void disconnect();

    Subscribable<SuccessfulConnectionListener> getSuccessfulConnectionSubscriptions();

    Subscribable<DisconnectionListener> getDisconnectionSubscriptions();

    Subscribable<FailedConnectionListener> getFailedConnectionSubscriptions();

    /**
     * Removes all listener subscriptions.
     */
    void unsubscribeAll();

    /**
     * Builds an implementation of the default facade implementation for the current library release.
     */
    public class Builder {

        /**
         * Builds and returns the instance.
         * @return Built instance
         */
        public static ClientFacade build() {
            return new DefaultClientFacadeImpl();
        }
    }
}
